<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/resources/jstl_contexpath.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title>虎丘婚纱城管理系统</title>
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/bs3/css/bootstrap.min.css" />" />
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/bootstrap-reset.css" />" />
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/font-awesome/css/font-awesome.css" />" />
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/clndr.css" />" />
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/style.css" />" />
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/style-responsive.css" />" />

    <!-- start: CSS -->
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/assets/css/bootstrap.min.css" />" />
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/assets/css/style.min.css" />" />
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/assets/css/retina.min.css" />" />
    <!-- end: CSS -->

    <!-- start: Favicon and Touch Icons -->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="<c:url value="/resources/assets/ico/apple-touch-icon-144-precomposed.png" />" />
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="<c:url value="/resources/assets/ico/apple-touch-icon-114-precomposed.png" />" />
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="<c:url value="/resources/assets/ico/apple-touch-icon-72-precomposed.png" />" />
    <link rel="apple-touch-icon-precomposed" sizes="57x57" href="<c:url value="/resources/assets/ico/apple-touch-icon-57-precomposed.png" />" />
    <link rel="shortcut icon" href="<c:url value="/resources/assets/ico/favicon.png" />" />
    <!-- end: Favicon and Touch Icons -->

</head>
<body>

    <!-- start: Header -->
    <%@ include file="/resources/head.jsp" %>
    <!-- end: Header -->

    <div class="container">
        <div class="row">
            <!-- start: Main Menu -->
            <%@ include file="/resources/sidebar.jsp" %>
            <!-- end: Main Menu -->

            <!-- start: Content -->
            <div id="content" class="col-lg-10 col-sm-11">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="box">
                            <div class="box-header">
                                <h2><i class="fa fa-align-justify"></i><span class="break"></span>角色权限管理</h2>
                                <div class="box-icon">
                                </div>
                            </div>
                            <div class="box-content">
                                <table class="table table-bordered table-striped table-condensed">
                                    <thead>
                                    <tr>
                                        <th>角色名称</th>
                                        <th>
                                            <select id="role">
                                                <c:forEach var="role" items="${role_list}" varStatus="status">
                                                    <c:if test="${is_user_admin == 1}">
                                                        <c:if test="${role.role_id == choose_role_id}">
                                                            <option value="${role.role_id}" selected="selected">${role.role_name}</option>
                                                        </c:if>
                                                        <c:if test="${role.role_id != choose_role_id}">
                                                            <option value="${role.role_id}">${role.role_name}</option>
                                                        </c:if>
                                                    </c:if>
                                                    <c:if test="${is_user_admin == 0}">
                                                        <c:if test="${role.role_id > 10000}">
                                                            <c:if test="${role.role_id == choose_role_id}">
                                                                <option value="${role.role_id}" selected="selected">${role.role_name}</option>
                                                            </c:if>
                                                            <c:if test="${role.role_id != choose_role_id}">
                                                                <option value="${role.role_id}">${role.role_name}</option>
                                                            </c:if>
                                                        </c:if>
                                                    </c:if>
                                                </c:forEach>
                                            </select>
                                        </th>
                                    </tr>
                                    </thead>
                                </table>
                                <table class="table table-bordered table-striped table-condensed">
                                    <thead>
                                    <tr>
                                        <td>权限</td>
                                        <td>
                                            <ul>
                                                <c:forEach var="top_menu" items="${top_menu_list}" varStatus="status">
                                                    <li>
                                                        <label class='checkbox inline'>${top_menu.menu_name}</label>
                                                        <ul>
                                                            <c:forEach var="sub_menu" items="${sub_menu_list}" varStatus="status">
                                                            <c:if test="${top_menu.menu_id == sub_menu.pid}">
                                                            <li>
                                                                <label>
                                                                    <c:if test="${sub_menu.role_menu_status == 1}">
                                                                        <input type='checkbox' name='sub_menu' value='${sub_menu.menu_id}' checked="true"/>&nbsp;${sub_menu.menu_name}
                                                                    </c:if>
                                                                    <c:if test="${sub_menu.role_menu_status != 1}">
                                                                        <input type='checkbox' name='sub_menu' value='${sub_menu.menu_id}' />&nbsp;${sub_menu.menu_name}
                                                                    </c:if>
                                                                </label>
                                                            </li>
                                                            </c:if>
                                                            </c:forEach>
                                                        </ul>
                                                    </li>
                                                </c:forEach>
                                            </ul>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tableleft"></td>
                                        <td>
                                            <button type="button" class="btn btn-primary" name="save" id="save">保存</button> &nbsp;&nbsp;
                                        </td>
                                    </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>
                    </div><!--/col-->
                </div>
            </div>
        </div>
    </div>
    <%@ include file="/resources/managerfoot.jsp"%>

    <!-- start: JavaScript-->
    <script type="text/javascript" src="<c:url value="/resources/assets/js/jquery-2.1.0.min.js" />" ></script>
    <script type="text/javascript" src="<c:url value="/resources/assets/js/jquery-migrate-1.2.1.min.js" />" ></script>
    <script type="text/javascript" src="<c:url value="/resources/assets/js/bootstrap.min.js" />" ></script>

    <!-- page scripts -->
    <script type="text/javascript" src="<c:url value="/resources/assets/js/jquery-ui-1.10.3.custom.min.js" />" ></script>
    <script type="text/javascript" src="<c:url value="/resources/assets/js/jquery.sparkline.min.js" />" ></script>
    <script type="text/javascript" src="<c:url value="/resources/assets/js/jquery.dataTables.min.js" />" ></script>
    <script type="text/javascript" src="<c:url value="/resources/assets/js/dataTables.bootstrap.min.js" />" ></script>

    <!-- theme scripts -->
    <script type="text/javascript" src="<c:url value="/resources/assets/js/custom.min.js" />" ></script>
    <script type="text/javascript" src="<c:url value="/resources/assets/js/core.min.js" />" ></script>

    <!-- inline scripts related to this page -->
    <script type="text/javascript" src="<c:url value="/resources/assets/js/pages/table.js" />" ></script>

    <!-- end: JavaScript-->

    <script>
        $(function () {
            $('#role').change(function(){
                var choose_role_id = $(this).children('option:selected').val();
                window.location.href="${ctx}/manage/system/rolemenu/index?choose_role_id="+choose_role_id;
            });
            $('#save').click(function(){
                var sub_menu_id='';
                $('input[name="sub_menu"]:checked').each(function(){
                    sub_menu_id+=$(this).val()+',';
                });
                var role_id = $('#role').val();
                $.ajax({
                    url:"${ctx}/manage/system/rolemenu/doconfig",
                    type: "post",
                    data:{sub_menu_id:sub_menu_id,role_id:role_id},
    //                dataType:"json",
                    success:function(data){
                        if(data == 1){
                            alert("成功");
                            location.reload();
                        } else {
                            alert("失败");
                        }
                    }
                })
            })
        });
    </script>



</body>
</html>